package reflect;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.Scanner;

/**
 * 通过Method访问方法常见信息
 */
public class ReflectDemo7 {
    public static void main(String[] args) throws ClassNotFoundException {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入类:");
        String classname =scanner.nextLine();
        Class cls = Class.forName(classname);
        Method[] methods = cls.getDeclaredMethods();
        for (Method method:methods){

            System.out.println("方法名:"+method.getName());
            System.out.println("参数个数:"+method.getParameterCount());
            System.out.println("参数类型:"+Arrays.toString(method.getGenericParameterTypes()));

            int modifiers = method.getModifiers();
            switch (modifiers){
                case Modifier.PUBLIC:
                    System.out.println("public");
                    break;
                case Modifier.PRIVATE:
                    System.out.println("private");
                    break;
                case Modifier.PROTECTED:
                    System.out.println("protected");
                    break;
            }
            System.out.println("---------------------");
        }
    }
}
